home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / Updates / PowerPC / pdflib / bind / cpp / pdfclock.cpp < prev    next >
C/C++ Source or Header  |  2000-05-16  |  4KB  |  146 lines

  1. /*---------------------------------------------------------------------------*
  2.  |        PDFlib - A library for dynamically generating PDF files            |
  3.  +---------------------------------------------------------------------------+
  4.  |        Copyright (c) 1997-1999 Thomas Merz. All rights reserved.          |
  5.  +---------------------------------------------------------------------------+
  6.  |    This software is not in the public domain.  It is subject to the       |
  7.  |    "Aladdin Free Public License".  See the file license.txt for details.  |
  8.  |    This license grants you the right to use and redistribute PDFlib       |
  9.  |    under certain conditions. Among other things, the license requires     |
  10.  |    that the copyright notice and this notice be preserved on all copies.  |
  11.  |    This requirement extends to ports to other programming languages.      |
  12.  |                                                                           |
  13.  |    In short, you are allowed to develop and use PDFlib-based software     |
  14.  |    as long as you don't sell it. Commercial use of PDFlib requires a      |
  15.  |    commercial license which can be obtained from the author of PDFlib.    |
  16.  |    Contact information can be found in the accompanying PDFlib manual.    |
  17.  |    PDFlib is distributed with no warranty of any kind. Commercial users,  |
  18.  |    however, will receive warranty and support statements in writing.      |
  19.  *---------------------------------------------------------------------------*/
  20.  
  21. // pdfclock.cpp
  22. //
  23. // A little PDFlib application to draw an analog clock.
  24. //
  25. //
  26.  
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include <time.h>
  31.  
  32. #if !defined(WIN32) && !defined(MAC)
  33. #include <unistd.h>
  34. #endif
  35.  
  36. #include "pdflib.hpp"
  37.  
  38. #define READMODE    "rb"
  39. #define RADIUS        200.0
  40. #define MARGIN        20.0
  41. #define BUFSIZE        512
  42.  
  43. #define FILENAME    "pdfclock_cpp.pdf"
  44.  
  45. int
  46. main()
  47. {
  48.     PDF        *p;
  49.     float    alpha;
  50.     time_t    timer;
  51.     struct tm    ltime;
  52.     
  53.     /* Create a new PDF object */
  54.     p = new PDF();
  55.  
  56.     /* Open new PDF file */
  57.     if (p->open(FILENAME) == -1) {
  58.     fprintf(stderr, "pdfclock error: cannot open PDF file %s.\n",
  59.         FILENAME);
  60.     }
  61.  
  62.     p->set_info("Creator", "pdfclock.cpp");
  63.     p->set_info("Author", "Thomas Merz");
  64.     p->set_info("Title", "PDF clock (C++)");
  65.  
  66.     p->begin_page((unsigned int) (2 * (RADIUS + MARGIN)),
  67.               (unsigned int) (2 * (RADIUS + MARGIN)));
  68.     
  69.     p->set_transition("wipe");
  70.     p->set_duration(0.5);
  71.  
  72.     p->translate(RADIUS + MARGIN, RADIUS + MARGIN);
  73.     p->setrgbcolor(0.0, 0.0, 1.0);
  74.     p->save();
  75.  
  76.     /* minute strokes */
  77.     p->setlinewidth(2.0);
  78.     for (alpha = 0; alpha < 360; alpha += 6)
  79.     {
  80.     p->rotate(6.0);
  81.     p->moveto(RADIUS, 0.0);
  82.     p->lineto((float) (RADIUS-MARGIN/3), 0.0);
  83.     p->stroke();
  84.     }
  85.  
  86.     p->restore();
  87.     p->save();
  88.  
  89.     /* 5 minute strokes */
  90.     p->setlinewidth(3.0);
  91.     for (alpha = 0; alpha < 360; alpha += 30)
  92.     {
  93.     p->rotate(30.0);
  94.     p->moveto(RADIUS, 0.0);
  95.     p->lineto(RADIUS-MARGIN, 0.0);
  96.     p->stroke();
  97.     }
  98.  
  99.     time(&timer);
  100.     ltime = *localtime(&timer);
  101.  
  102.     /* draw hour hand */
  103.     p->save();
  104.     p->rotate(
  105.         (float)(-((ltime.tm_min/60.0) + ltime.tm_hour - 3.0) * 30.0));
  106.     p->moveto(-RADIUS/10, -RADIUS/20);
  107.     p->lineto(RADIUS/2, 0.0);
  108.     p->lineto(-RADIUS/10, RADIUS/20);
  109.     p->closepath();
  110.     p->fill();
  111.     p->restore();
  112.  
  113.     /* draw minute hand */
  114.     p->save();
  115.     p->rotate((float) (-((ltime.tm_sec/60.0) + ltime.tm_min - 15.0) * 6.0));
  116.     p->moveto(-RADIUS/10, -RADIUS/20);
  117.     p->lineto(RADIUS * 0.8, 0.0);
  118.     p->lineto(-RADIUS/10, RADIUS/20);
  119.     p->closepath();
  120.     p->fill();
  121.     p->restore();
  122.  
  123.     /* draw second hand */
  124.     p->setrgbcolor(1.0, 0.0, 0.0);
  125.     p->setlinewidth(2);
  126.     p->save();
  127.     p->rotate((float) -((ltime.tm_sec - 15.0) * 6.0));
  128.     p->moveto(-RADIUS/5, 0.0);
  129.     p->lineto(RADIUS, 0.0);
  130.     p->stroke();
  131.     p->restore();
  132.  
  133.     /* draw little circle at center */
  134.     p->circle(0, 0, (float) RADIUS/30);
  135.     p->fill();
  136.  
  137.     p->restore();
  138.  
  139.     p->end_page();
  140.  
  141.     p->close();
  142.  
  143.     exit(0);
  144.     return (0);
  145. }
  146.